package com.itheima02.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima02.bean.Student;
import com.itheima02.service.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class StudentController {
    StudentServiceImpl service = new StudentServiceImpl();

    @Test
    public void findByIds(){
        List<Integer> ids = new ArrayList<>();
        ids.add(1);
        ids.add(2);
        ids.add(3);
        List<Student> list = service.findByIds(ids);
        for (Student student : list) {
            System.out.println(student);
        }
    }

    @Test
    public void findByNameOrAge() {
        List<Student>  list= service.findByNameOrAge("张三",24);
        for (Student student : list) {
            System.out.println(student);
        }
    }

    @Test
    public void findCondition(){
        Student stu = new Student();
        stu.setId(1);
        stu.setName("张三");
        List<Student> list = service.findCondition(stu);
        for (Student student : list) {
            System.out.println(student);
        }
    }

    @Test
    public void selectAll() {
        //PageHelper.startPage(1,3);
        //PageHelper.startPage(2,3);
        PageHelper.startPage(3,3);
        List<Student> list = service.selectAll();
        for (Student student : list) {
            System.out.println(student);
        }
        PageInfo<Student> page = new PageInfo<>(list);
        System.out.println("总条数：" +page.getTotal());
        System.out.println("总页数：" +page.getPages());
        System.out.println("当前页："+page.getPageNum());
        System.out.println("每页显示条数："+page.getPageSize());
        System.out.println("上一页："+page.getPrePage());
        System.out.println("下一页: "+page.getNextPage());
        System.out.println("是否是第一页："+page.isIsFirstPage());
        System.out.println("是否是最后一页："+page.isIsLastPage());
    }

    @Test
    public void selectById() {
        Student stu = service.selectById(2);
        System.out.println(stu);
    }

    @Test
    public void insert() {
        Student stu = new Student(3, "搜索", 23);
        int res = service.insert(stu);
        System.out.println(res);
    }

    @Test
    public void delete() {
        int res = service.delete(4);
        System.out.println(res);
    }

    @Test
    public void update() {
        Student stu = new Student(3, "淋淋", 22);
        int res = service.update(stu);
        System.out.println(res);
    }
}
